package com.binc.testspring.study.xml_json;

import com.binc.testspring.study.xml_json.beans.*;
import com.binc.testspring.util.DateUtil;
import org.junit.Test;

import java.util.Map;

/**
 * Copyright (C), 2019-2021, XXX 奇限公司
 * FileName: TestXmlUtil
 * Autho: binC
 * Date:  2021/11/26 10:21
 * Description:
 * History:
 * <author>     <time>      <version>       <desc>
 * 作者姓名       修改时间      版本          描述
 */
public class TestXmlUtil
{
    static FOX fox;

    static {
        SONRQ sonrq = new SONRQ();
        sonrq.setDTCLIENT(DateUtil.getStringDate());

        sonrq.setCID("cid_123");
        sonrq.setUSERID("userId");
        sonrq.setUSERPASS("userPass");
        sonrq.setGENUSERKEY("N");

        //转出账户
        ACCTFROM acctfrom = new ACCTFROM();
        acctfrom.setACCTID("setACCTID");

        //转入账户
        ACCTTO acctto = new ACCTTO();
        acctto.setINTERBANK("setINTERBANK");
        acctto.setLOCAL("setLOCAL");
        acctto.setACCTID("setACCTID(");
        acctto.setNAME("name");
        acctto.setBANKDESC("bankdesc");
        acctto.setBANKNUM("banknum");
        acctto.setCITY("city");

        //信息
        XFERINFO xferinfo = new XFERINFO();
        xferinfo.setACCTFROM(acctfrom);
        xferinfo.setACCTTO(acctto);
        xferinfo.setCHEQUENUM("");
        xferinfo.setTRNAMT("tranmt");
        xferinfo.setPURPOSE("purpose");
        xferinfo.setMEMO("meno");

        //转账指令
        XFERRQ xferrq = new XFERRQ();
        xferrq.setXFERINFO(xferinfo);

        XFERTRNRQ xfertrnrq = new XFERTRNRQ();
        xfertrnrq.setTRNUID("truniddddd");
        xfertrnrq.setXFERRQ(xferrq);

        SIGNONMSGSRQV1 signOnMsgSrqV1 = new SIGNONMSGSRQV1();
        signOnMsgSrqV1.setSONRQ(sonrq);

        SECURITIES_MSGSRQV1 securities_msgsrqv1 = new SECURITIES_MSGSRQV1();
        securities_msgsrqv1.setXFERTRNRQ(xfertrnrq);

        fox = new FOX();
        fox.setSIGNONMSGSRQV1(signOnMsgSrqV1);
        fox.setSECURITIES_MSGSRQV1(securities_msgsrqv1);
    }


    @Test
    public void test(){
        String s = XmlUtil.toString(fox);
        System.out.println(s);
        /*
<FOX>
   <SIGNONMSGSRQV1>
      <SONRQ>
         <DTCLIENT>2021-11-26 10:27:05</DTCLIENT>
         <CID>cid_123</CID>
         <USERID>userId</USERID>
         <USERPASS>userPass</USERPASS>
         <GENUSERKEY>N</GENUSERKEY>
         <APPID>XYFIB</APPID>
         <APPVER>1000</APPVER>
      </SONRQ>
   </SIGNONMSGSRQV1>
   <SECURITIES_MSGSRQV1>
      <XFERTRNRQ>
         <TRNUID>truniddddd</TRNUID>
         <XFERRQ>
            <XFERINFO>
               <ACCTFROM>
                  <ACCTID>setACCTID</ACCTID>
               </ACCTFROM>
               <ACCTTO INTERBANK="setINTERBANK" LOCAL="setLOCAL">
                  <ACCTID>setACCTID(</ACCTID>
                  <NAME>name</NAME>
                  <BANKDESC>bankdesc</BANKDESC>
                  <BANKNUM>banknum</BANKNUM>
                  <CITY>city</CITY>
               </ACCTTO>
               <CHEQUENUM></CHEQUENUM>
               <TRNAMT>tranmt</TRNAMT>
               <PURPOSE>purpose</PURPOSE>
               <MEMO>meno</MEMO>
            </XFERINFO>
         </XFERRQ>
      </XFERTRNRQ>
   </SECURITIES_MSGSRQV1>
</FOX>
         */
    }



    @Test
    public void test2(){
        String xmlStr = "<FOX>\n" +
                "   <SIGNONMSGSRQV1>\n" +
                "      <SONRQ>\n" +
                "         <DTCLIENT>2021-11-26 10:27:05</DTCLIENT>\n" +
                "         <CID>cid_123</CID>\n" +
                "         <USERID>userId</USERID>\n" +
                "         <USERPASS>userPass</USERPASS>\n" +
                "         <GENUSERKEY>N</GENUSERKEY>\n" +
                "         <APPID>XYFIB</APPID>\n" +
                "         <APPVER>1000</APPVER>\n" +
                "      </SONRQ>\n" +
                "   </SIGNONMSGSRQV1>\n" +
                "   <SECURITIES_MSGSRQV1>\n" +
                "      <XFERTRNRQ>\n" +
                "         <TRNUID>truniddddd</TRNUID>\n" +
                "         <XFERRQ>\n" +
                "            <XFERINFO>\n" +
                "               <ACCTFROM>\n" +
                "                  <ACCTID>setACCTID</ACCTID>\n" +
                "               </ACCTFROM>\n" +
                "               <ACCTTO INTERBANK=\"setINTERBANK\" LOCAL=\"setLOCAL\">\n" +
                "                  <ACCTID>setACCTID(</ACCTID>\n" +
                "                  <NAME>name</NAME>\n" +
                "                  <BANKDESC>bankdesc</BANKDESC>\n" +
                "                  <BANKNUM>banknum</BANKNUM>\n" +
                "                  <CITY>city</CITY>\n" +
                "               </ACCTTO>\n" +
                "               <CHEQUENUM></CHEQUENUM>\n" +
                "               <TRNAMT>tranmt</TRNAMT>\n" +
                "               <PURPOSE>purpose</PURPOSE>\n" +
                "               <MEMO>meno</MEMO>\n" +
                "            </XFERINFO>\n" +
                "         </XFERRQ>\n" +
                "      </XFERTRNRQ>\n" +
                "   </SECURITIES_MSGSRQV1>\n" +
                "</FOX>";

        Object o = XmlUtil.toObject(xmlStr, FOX.class);
        FOX f = (FOX) o;
        System.out.println(f);
        System.out.println("--------------------");

        Map<String, String> stringStringMap = XmlUtil.toMap(xmlStr);
        System.out.println(stringStringMap);

    }


}
